var majiang = {};
var roomid;
var userid;
var userno;

function initmajiang(roomid, userid, position) {
	majiang = {
		roomid : roomid,
		userid : userid,
		userno : 'u' + position
	};
	roomid = roomid;
	userid = userid;
	userno = position - 0;
}

function sendCommand() {
	var command = majiang;
	createJson(command, "command", "test")
	sendMessage(command);
}

function getMJRoom() {
	var command = majiang;
	createJson(command, "command", "MJ1001")
	sendMessage(command);
}

function MJ1002() {
	var command = majiang;
	createJson(command, "command", "MJ1002")
	sendMessage(command);
}

function MJ1003(mj) {
	$("#gangpeng").empty();
	$("#chi").empty();
	$("#playmj").empty();
	var command = majiang;
	createJson(command, "command", "MJ1003")
	createJson(command, "mj", mj)
	sendMessage(command);
}
function MJ1004(mj) {
	$("#gangpeng").empty();
	$("#chi").empty();
	$("#playmj").empty();
	clearTimeout(gpTimeout);
	var command = majiang;
	createJson(command, "command", "MJ1004")
	createJson(command, "mj", mj)
	sendMessage(command);
}
function MJ1005(mj) {
	$("#gangpeng").empty();
	$("#chi").empty();
	$("#playmj").empty();
	clearTimeout(gpTimeout);
	var command = majiang;
	createJson(command, "command", "MJ1005")
	createJson(command, "mj", mj)
	sendMessage(command);
}

function createJson(command, prop, val) {
	// 如果 val 被忽略
	if (typeof val === "undefined") {
		// 删除属性
		delete command[prop];
	} else {
		// 添加 或 修改
		command[prop] = val;
	}
}